import { getAreaObj, regularRule, uploadType } from '@/utils/util'
import apiMod from '@/apiMod'

export const OtherFormConfig = {
	label: '其他信息',
	prop: 'dp_service_object_other',
	inline: false,
	showBtn: false,
	labelPosition: 'left',
	column: [
		//--------------------经济状况 ----------------
		{
			type: 'DividerHtml',
			modelValue: '经济状况',
			span: 24,
		},
		{
			label: '个人年收入',
			prop: 'annualSalary',
			type: 'input',
			append: '（元）',
			rules: [{ validator: regularRule.number, message: '请输入正确的数量' }],
			span: 8,
		},
		{
			label: '家庭年收入',
			prop: 'familySalary',
			type: 'input',
			append: '（元）',
			rules: [{ validator: regularRule.number, message: '请输入正确的数量' }],
			span: 8,
		},
		{
			label: '经济状况',
			prop: 'economicSituation',
			propName: 'economicSituationLabel',
			type: 'remoteSelect',
			code: 'ECONOMIC_SITUATION',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '收入来源',
			prop: 'incomeSource',
			propName: 'incomeSourceLabel',
			type: 'remoteSelect',
			code: 'INCOME_SOURCE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '年度可支配收入',
			prop: 'disposableIncome',
			propName: 'disposableIncomeLabel',
			type: 'remoteSelect',
			code: 'DISPOSABLE_INCOME',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '经济困难证明',
			prop: 'economicHardship',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 12,
		},
		//--------------------居住条件 ----------------
		{
			type: 'DividerHtml',
			modelValue: '居住条件',
			span: 24,
		},
		{
			label: '所属机构名称',
			prop: 'orgName',
			type: 'input',
			span: 8,
		},
		{
			label: '所属机构统一信用代码',
			prop: 'creditCode',
			type: 'input',
			span: 8,
		},
		{
			label: '住房性质',
			prop: 'housingProperty',
			propName: 'housingPropertyLabel',
			code: 'HOUSEING_PROPERTY',
			type: 'remoteSelect',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '居室',
			prop: 'liveRoom',
			propName: 'liveRoomLabel',
			type: 'remoteSelect',
			code: 'LIVE_ROOM',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '是否有出入无障碍设施',
			prop: 'isAccessibility',
			propName: 'isAccessibilityLabel',
			type: 'select',
			span: 8,
			dicData: [
				{ label: '是', value: 1 },
				{ label: '否', value: 0 },
			],
		},
		{
			label: '是否有楼层电梯',
			prop: 'isElevator',
			propName: 'isElevatorLabel',
			type: 'select',
			span: 8,
			dicData: [
				{ label: '是', value: 1 },
				{ label: '否', value: 0 },
			],
		},
		{
			label: '居住楼层（楼层无电梯的）',
			prop: 'liveFloor',
			propName: 'liveFloorLabel',
			type: 'remoteSelect',
			code: 'LIVE_FLOOR',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '是否有室内厕所',
			prop: 'isToilet',
			propName: 'isToiletLabel',
			type: 'select',
			span: 8,
			dicData: [
				{ label: '是', value: 1 },
				{ label: '否', value: 0 },
			],
		},
		{
			label: '是否有室内洗浴设备',
			prop: 'isBathEquipment',
			propName: 'isBathEquipmentLabel',
			type: 'select',
			span: 8,
			dicData: [
				{ label: '是', value: 1 },
				{ label: '否', value: 0 },
			],
		},
		{
			label: '是否有室内无障碍设施',
			prop: 'isIndoorAccessibility',
			propName: 'isIndoorAccessibilityLabel',
			type: 'select',
			span: 8,
			dicData: [
				{ label: '是', value: 1 },
				{ label: '否', value: 0 },
			],
		},
		{
			label: '是否有室内洗浴设施',
			prop: 'isBathingFacilities',
			propName: 'isBathingFacilitiesLabel',
			type: 'select',
			span: 8,
			dicData: [
				{ label: '是', value: 1 },
				{ label: '否', value: 0 },
			],
		},
		{
			label: '是否有居住安全风险',
			prop: 'isSafetyRisks',
			propName: 'isSafetyRisksLabel',
			type: 'select',
			span: 8,
			dicData: [
				{ label: '是', value: 1 },
				{ label: '否', value: 0 },
			],
		},
		{
			label: '是否完成适老化改造',
			prop: 'isRetrofit',
			propName: 'isRetrofitLabel',
			type: 'select',
			dicData: [
				{ label: '是', value: 1 },
				{ label: '否', value: 0 },
			],
			span: 8,
		},
		{
			label: '备注',
			prop: 'note',
			type: 'textarea',
			maxlength: '140',
			span: 24,
			showWordLimit: true,
		},
		//--------------------健康诊断内容 ----------------
		{
			type: 'DividerHtml',
			modelValue: '健康诊断内容',
			span: 24,
		},
		{
			label: '健康诊断结论',
			prop: 'healthConclusion',
			type: 'textarea',
			maxlength: '50',
			rules: [{ required: true, message: '请输入健康诊断结论' }],
			rows: 1,
			showWordLimit: true,
			span: 8,
		},
		{
			label: '过敏物',
			prop: 'allergens',
			type: 'textarea',
			maxlength: '50',
			rows: 1,
			showWordLimit: true,
			span: 8,
		},
		{
			label: '症状描述',
			prop: 'symptomDescription',
			type: 'textarea',
			maxlength: '140',
			rows: 1,
			showWordLimit: true,
			span: 8,
		},
		{
			label: '用药时间段',
			prop: 'dosingTime',
			type: 'textarea',
			maxlength: '140',
			rows: 1,
			showWordLimit: true,
			span: 12,
		},
		{
			label: '用药描述',
			prop: 'medicationDescription',
			type: 'textarea',
			maxlength: '140',
			rows: 1,
			showWordLimit: true,
			span: 12,
		},
		{
			label: '体征数据',
			prop: 'signsData',
			type: 'textarea',
			maxlength: '140',
			rows: 1,
			showWordLimit: true,
			span: 12,
		},
		{
			label: '备注',
			prop: 'healthDiagnosisNote',
			type: 'textarea',
			maxlength: '140',
			rows: 1,
			showWordLimit: true,
			span: 12,
		},
	],
}

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ type: 'selection', fixed: 'left', reserveSelection: true },
		{ label: '户籍地区', prop: 'crAreaInfoName' },
		{ label: '证件号码', prop: 'idCard', plusXing: '2,2' },
		{ label: '姓名', prop: 'name' },
		{
			label: '性别',
			prop: 'genderLabel',
		},
		{ label: '年龄', prop: 'age' },
		{ label: '联系方式', prop: 'telephone', plusXing: '5,2' },
		{ label: '现居地区', prop: 'address' },
		{
			label: '老人类别',
			prop: 'elderlyType',
			custome: 'dict',
			code: 'ELDERLY_TYPE',
		},
		{
			label: '居住情况',
			prop: 'residence',
			custome: 'dict',
			code: 'LIVE_SITUATE',
		},
		{
			label: '评估状态',
			prop: 'evaluationStatusLabel',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const rechangeConfig = {
	label: '变更材料',
	prop: 'dp_service_object_other',
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	submitBtnText: '确认并提交',
	backBtnText: '返回修改内容',
	column: [
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '变更内容',
			span: 24,
		},
		{
			prop: 'content',
			type: 'input',
			span: 24,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '变更材料',
			span: 24,
		},
		{
			label: '情况说明',
			prop: 'changeDescription',
			type: 'textarea',
			maxlength: '140',
			rows: 2,
			showWordLimit: true,
			span: 24,
		},
		{
			label: '证明材料',
			prop: 'changeMaterials',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
		},
	],
}

export const baseConfig = {
	pageName: '服务对象管理',
	dictcodes: [
		'CHILDREN_SITUATION',
		'HOUSEING_PROPERTY',
		'LIVE_FLOOR',
		'LIVE_ROOM',
		'LIVE_TIME',
		'ID_CARD_TYPE',
		'REG_RESIDENCE_TYPE',
		'EXISTENCE_STATUS',
		'ELDERLY_DEMAND',
		'DISABILITY_TYPE',
		'DISABILITY_CLASS',
		'ELDERLY_TYPE',
		'BLOOD_TYPE',
		'NATIONALITY',
		'MARITAL_STATUS',
		'NURSE_TYPE',
		'OLDMAN_ZODIAC',
		'POLITICAL_STATUS',
		'ENJOY_TREATMENT',
		'SOCIAL_SECURITY',
		'EDUCATION_DEGREE',
		'RETIRE_TYPE',
		'RETIRE_WORK',
		'MEDICAL_SECURITY',
		'CARE_SITUATION',
		'SOCIAL_ACTIVITIES_SITUATE',
		'SOCIAL_ACTIVITIES_TYPE',
		'SPECIALTY',
		'MATERIAL_DATA_TYPE',
		'ELDERLY_RELATIONSHIP',
		'ECONOMIC_SITUATION',
		'INCOME_SOURCE',
		'DISPOSABLE_INCOME',
		'ACCESS_LEVEL_COUNTRY',
		'ACCESS_LEVEL_CITY',
		'LIVE_SITUATE',
		'RELIGIOUS_BELIEF',
		'SENIOR_LIVING',
		'EVALUATION_STATUS',
		'OSF_TASK_TYPE',
		'OST_TASK_LEVEL',
	],
	rowKey: 'id',
	addLabel: '采集数据',
	tipLabel: 'name',
	exportMqTopic: [
		{
			topic: '/ning/export/dpServiceObject/',
			label: '基础数据',
			code: 1001,
			po: 'dpServiceObjectPO',
		},
		{
			topic: '/ning/export/dpServiceObjectExtend/',
			label: '扩展信息',
			code: 1003,
			po: 'dpServiceObjectExtendPO',
		},
		{
			topic: '/ning/export/dpServiceObjectContact/',
			label: '联系人信息',
			code: 1002,
			po: 'dpServiceObjectContactPO',
		},
		{
			topic: '/ning/export/dpServiceObjectOther/',
			label: '其他信息',
			code: 1005,
			po: 'dpServiceObjectOtherPO',
		},
		{
			topic: '/ning/export/dpServiceObjectMaterial/',
			label: '材料信息',
			code: 1004,
			po: 'dpServiceObjectMaterialPO',
		},
	],
	api: {
		index: 'view_dpServiceObject_page',
		// add: 'view_dpServiceObject_gather',
		count: 'view_dpServiceObject_count',
		edit: 'view_dpServiceObjectOther_edit',
		delete: 'view_dpServiceObject_del',
		// export: 'view_dpServiceObject_exportAll',
	},
	auth: {
		index: 'view_dpServiceObject_page',
		// add: 'view_dpServiceObject_gather',
		edit: 'view_dpServiceObjectOther_edit',
		delete: 'view_dpServiceObject_del',
		// mulitSet: 'mulitSet',
		// export: 'view_dpServiceObject_exportAll',
		// import: 'view_dpServiceObject_page',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'sys_role_edit',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '90%',
		// fullscreen: true
	},
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '姓名',
				prop: 'name',
				type: 'input',
				span: 6,
			},
			{
				label: '证件号码',
				prop: 'idCard',
				type: 'input',
				span: 6,
			},
			{
				label: '评估状态',
				prop: 'evaluationStatus',
				code: 'EVALUATION_STATUS',
				type: 'remoteSelect',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
			{
				label:"年龄区间",
				prop:"ageBetween",
				type:"RangeValue",
				span: 12,
			}
		],
	},
	formConfig: {
		...OtherFormConfig,
		showBtn: true,
	},
	detailConfig: {
		customeHeader: {
			type: 'CardTwo',
			title: 'name',
			avatar: 'image',
			tipList: [{ prop: 'organizationName', type: 'tip-success', label: '服务组织' }],
			tagList: [
				{ prop: 'countryLevel', custome: 'tag', type: 'success', label: '能力等级' },
				{ prop: 'birthday', type: 'success', label: '（公历）' },
				{ prop: 'lunarBirthday', type: 'success', label: '（农历）' },
			],
			menuBtn: [
				{
					icon: 'delete',
					label: '删除服务对象',
					type: 'danger',
					operate: 'delete',
					auth: 'view_dpServiceObject_del',
					hide: 'dataStatus==0',
					text: false,
					show: true,
					plain: true,
				},
			],
		},
	},
	moreSearchConfig: {},
	tableConfig,
	beforeOnLoadFormate: async (params) => {
		return Promise.resolve({
			...params,
			areas: undefined,
			crAreas: undefined,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const crAreaInfoName = getAreaObj(item, 'cr')
			const areas_name = getAreaObj(item, '')
			return {
				...item,
				areas_name,
				crAreaInfoName,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	operateFormate: async (form, type) => {
		return new Promise((resolve, reject) => {
			if (type == 'edit') {
				apiMod.view_dpServiceObjectOther_page({ idCard: form.idCard }).then((res) => {
					const data = res.data.records[0] || {}
					resolve({
						id: form.id,
						...data,
						idCard: form.idCard,
					})
				})
			} else {
				resolve(form)
			}
		})
	},
}
